package org.watchrecords.elements.list;

import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;

public class ListEditorItem<T> extends Item<T> {
    /**
     * 
     */
    private static final long serialVersionUID = -8358893660596914532L;

    public ListEditorItem(String id, int index) {
        super(id, index);
        setModel(new ListItemModel());
    }

    private class ListItemModel implements IModel<T> {
        /**
     * 
     */
        private static final long serialVersionUID = -7825942261067082348L;

        @SuppressWarnings("unchecked")
        public T getObject() {
            return ((ListEditor<T>) ListEditorItem.this.getParent()).items.get(getIndex());
        }

        @SuppressWarnings("unchecked")
        @Override
        public void setObject(T obj) {
            ((ListEditor<T>) ListEditorItem.this.getParent()).items.set(getIndex(), obj);
        }

        @Override
        public void detach() {
            
        }
    }
}
